<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改公告咨询')" />
    <th:block th:include="include :: summernote-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-notice-edit" th:object="${crNotice}">
            <input name="noticeId" th:field="*{noticeId}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label">标题：</label>
                <div class="col-sm-8">
                    <input name="title" th:field="*{title}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">类型，0行业，1债权：</label>
                <div class="col-sm-8">
                    <select name="type" class="form-control m-b" th:with="type=${@dict.getType('notice_type')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{type}"></option>
                    </select>
                </div>
            </div>
<!--            <div class="form-group">    -->
<!--                <label class="col-sm-3 control-label">热点推荐，0 否，1是：</label>-->
<!--                <div class="col-sm-8">-->
<!--                    <input name="isHot" th:field="*{isHot}" class="form-control" type="text">-->
<!--                </div>-->
<!--            </div>-->
<!--             <div class="form-group">     -->
<!--                 <label class="col-sm-3 control-label">封面图：</label> -->
<!--                 <div class="col-sm-8"> -->
<!--                     <input name="image" th:field="*{image}" class="form-control" type="text"> -->
<!--                 </div> -->
<!--             </div> -->
<!--             <div class="form-group">     -->
<!--                 <label class="col-sm-3 control-label">封面缩略图：</label> -->
<!--                 <div class="col-sm-8"> -->
<!--                     <input name="subImage" th:field="*{subImage}" class="form-control" type="text"> -->
<!--                 </div> -->
<!--             </div> -->
            <div class="form-group">
                <label class="col-sm-3 control-label">封面图：</label>
                <div class="col-sm-8">
                    <input type="hidden" name="image" id="image" th:field="*{image}">
                    <div class="layui-upload-drag" id="imgPathw">
                        <i class="layui-icon"></i>
                        <p><span style="color: red;">点击上传，或将图片拖拽到此处</span></p >
                        <div class="layui-hide" id="imgPaths">
                            <hr>
                            <img src="" alt="上传成功后渲染" style="max-width: 196px">
                        </div>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">封面缩略图：</label>
                <div class="col-sm-8">
                    <input type="hidden" name="subImage" id="subImage" th:field="*{subImage}">
                    <div class="layui-upload-drag" id="subImagePathw">
                        <i class="layui-icon"></i>
                        <p><span style="color: red;">点击上传，或将图片拖拽到此处</span></p >
                        <div class="layui-hide" id="subImagePaths">
                            <hr>
                            <img src="" alt="上传成功后渲染" style="max-width: 196px">
                        </div>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">公告详情：</label>
                <div class="col-sm-8">
                    <input type="hidden" class="form-control" th:field="*{content}">
                    <div class="summernote" id="content"></div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: summernote-js" />
    <script th:inline="javascript">
        var prefix = ctx + "business/notice";
        $("#form-notice-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-notice-edit').serialize());
            }
        }

        $(function() {
            $('.summernote').each(function(i) {
                $('#' + this.id).summernote({
                    lang: 'zh-CN',
                    dialogsInBody: true,
                    callbacks: {
                        onChange: function(contents, $edittable) {
                            $("input[name='" + this.id + "']").val(contents);
                        },
                        onImageUpload: function(files) {
                            var obj = this;
                            var data = new FormData();
                            data.append("file", files[0]);
                            $.ajax({
                                type: "post",
                                url: ctx + "common/upload",
                                data: data,
                                cache: false,
                                contentType: false,
                                processData: false,
                                dataType: 'json',
                                success: function(result) {
                                    if (result.code == web_status.SUCCESS) {
                                        $('#' + obj.id).summernote('insertImage', result.url);
                                    } else {
                                        $.modal.alertError(result.msg);
                                    }
                                },
                                error: function(error) {
                                    $.modal.alertWarning("图片上传失败。");
                                }
                            });
                        }
                    }
                });
                var content = $("input[name='" + this.id + "']").val();
                $('#' + this.id).summernote('code', content);
            })
        });
        
        layui.use('upload',function() {
            var $ = layui.jquery, upload = layui.upload;
            upload.render({
                elem: '#imgPathw',
                url: ctx + 'common/upload',
                done: function(res){
                    layer.msg(res.msg);
                    if(res.code == 0){
                        layui.$('#imgPaths').removeClass('layui-hide').find('img').attr('src', res.url);
                        $('#image').val(res.url);
                    }
                }
            });
        });
        layui.use('upload',function() {
            var $ = layui.jquery, upload = layui.upload;
            upload.render({
                elem: '#subImagePathw',
                url: ctx + 'common/upload',
                done: function(res){
                    layer.msg(res.msg);
                    if(res.code == 0){
                        layui.$('#subImagePaths').removeClass('layui-hide').find('img').attr('src', res.url);
                        $('#subImage').val(res.url);
                    }
                }
            });
        });
    </script>
</body>
</html>